package com.yutel.phone.binh.comm;

public class StrUtil {

	public static String ToDBC(String input) {
		if (input == null) return "" ;
		char[] c = input.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if (c[i] == 12288) {
				c[i] = (char) 32;
				continue;
			}
			if (c[i] > 65280 && c[i] < 65375) {
				c[i] = (char) (c[i] - 65248);
			}
		}
		return new String(c);
	}
	public static String ToBC(String input) {
		if (input == null) return "" ;
		char[] c = input.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if(c[i]==32) {
				c[i]=(char)12288;
			}
			if (c[i] > 32 && c[i] < 127) {
				c[i] = (char) (c[i] + 65248);
			}
		}
		return new String(c);
	}
	public static String export(String input) {
		if (input == null) return "" ;
		StringBuffer sb=new StringBuffer(input);
		for (int i = 0; i < sb.length(); i++) {
			char c=sb.charAt(i);
			if(c<48) {
				sb.deleteCharAt(i--);
			} else if (c > 57 && c < 65) {
				sb.deleteCharAt(i--);
			} else if (c > 90 && c < 97) {
				sb.deleteCharAt(i--);
			} else if (c > 122 && c < 128) {
				sb.deleteCharAt(i--);
			} else if (c > 8207 && c < 8232) {
				sb.deleteCharAt(i--);
			} else if (c > 12288 && c < 12444) {
				sb.deleteCharAt(i--);
			} else if (c > 65280 && c < 65296) {//
				sb.deleteCharAt(i--);
			} else if (c > 65305 && c < 65313) {
				sb.deleteCharAt(i--);
			} else if (c > 65338 && c < 65345) {
				sb.deleteCharAt(i--);
			} else if (c > 65370 && c < 65382) {
				sb.deleteCharAt(i--);
			} else if(c==65509) {
				sb.deleteCharAt(i--);
			}
		}
		return sb.toString();
	}
	public static boolean isChinese(char c) {
		Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
		if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
				|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
				|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
				|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
				|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
				|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
			return true;
		}
		return false;
	}
	public static boolean checkNameChese(String name) {
		boolean res = true;
		char[] cTemp = name.toCharArray();
		for (int i = 0; i < name.length(); i++) {
			if (!isChinese(cTemp[i])) {
				res = false;
				break;
			}
		}
		return res;
	}
}
